using NUnit.Behave;
using NUnit.Framework;

namespace BehavioralExample
{
    [TestFixture]
    public class Account_Specs
    {


        [Test]
        public void Transfer_to_cash_account()
        {
			Story transfrer_to_cash_account = new Story("Transfer to cash account");

			transfrer_to_cash_account.As_a("savings account holder")
				.I_want("to transfer money from my savings account")
				.So_that("I can get cash easily from an ATM");

            Account savings = null;
            Account cash = null;

            Scenario savings_account_is_in_credit = new Scenario("savings account is in credit");
            
            savings_account_is_in_credit
                .Given("my savings account balance is", 100,
                       delegate(int accountBallance)
                           {
                               savings = new Account(accountBallance);
                           })
                .And("my cash account balance is", 10,
                     delegate(int accountBallance)
                         {
                             cash = new Account(accountBallance);
                         })
                .When("I transfer to cash account", 20,
                      delegate(int transferAmount)
                          {
                              savings.TransferTo(cash, transferAmount);
                          })
                .Then("my savings account balance should be", 80,
                      delegate(int expectedBallance)
                          {
                              Assert.AreEqual(expectedBallance, savings.Ballance);
                          })
                .And("my cash account balance should be", 30,
                     delegate(int expectedBallance)
                         {
                             Assert.AreEqual(expectedBallance, cash.Ballance);
                         });


            savings_account_is_in_credit
                .Given("my savings account balance is", 400)
                .And("my cash account balance is", 100)
                .When("I transfer to cash account", 100)
                .Then("my savings account balance should be", 300)
                .And("my cash account balance should be", 200);
        }
    }
}

public class Account
{
    private int accountBallance;

    public Account(int accountBallance)
    {
        this.accountBallance = accountBallance;
    }

    public int Ballance
    {
        get { return accountBallance; }
        set { accountBallance = value; }
    }

    public void TransferTo(Account account, int amount)
    {
        if (accountBallance > 0)
        {
            account.Ballance = account.Ballance + amount;
            Ballance = Ballance - amount;
        }
    }
}